package api.txNativeMould;

import android.content.Context;
import android.view.View;

import java.lang.ref.SoftReference;

/**
 * 原生模板模式
 */
public abstract class NativeMouldAPI_TX {

    public static String clazz = "api.txNativeMould.TX_NativeMould";

    private static SoftReference<NativeMouldAPI_TX> sf;

    public synchronized static NativeMouldAPI_TX getInstance() {

        if (sf == null || sf.get() == null) {
            Object o = null;
            try {
                o = Class.forName(clazz).newInstance();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
            if (o != null) {
                sf = new SoftReference<>((NativeMouldAPI_TX) o);
                return (NativeMouldAPI_TX) o;
            }
        }
        return sf == null ? null : sf.get();
    }

    public abstract void loadNativeMould(Context context, int loadCount,  String NativePosID, LoadNativeMouldCallBack callBack);

    public abstract void nativeMouldViewDestroy();

    public interface LoadNativeMouldCallBack {

        void onLoaded(View view);

        void onRenderFail();

        void onExposure();

        void onClosed();

        void onLeftApplication();

        void onNo(int code, String msg);

        void onClicked();

        void onRenderSuccess();
    }
}
